<template>
  <!-- 排序区域 -->
  <div class="sub-sort">
    <div class="sort">
      <a
        @click="changeSort(item.value)"
        :class="{ active: currSort === item.value }"
        v-for="item in sortList"
        :key="item.name"
        href="javascript:;"
        >{{ item.name }}</a
      >
      <!-- <a
        @click="changeSort('publishTime')"
        :class="{ active: currSort === 'publishTime' }"
        href="javascript:;"
        >最新商品</a
      >
      <a
        @click="changeSort('orderNum')"
        :class="{ active: currSort === 'orderNum' }"
        href="javascript:;"
        >最高人气</a
      >
      <a
        @click="changeSort('evaluateNum')"
        :class="{ active: currSort === 'evaluateNum' }"
        href="javascript:;"
        >评论最多</a
      > -->
    </div>
  </div>
</template>
<script>

import { ref, inject } from 'vue'
const sorts = [
  { name: '默认排序', value: null },
  { name: '最新商品', value: 'publishTime' },
  { name: '最高人气', value: 'orderNum' },
  { name: '评论最多', value: 'evaluateNum' }]
export default {
  name: 'SubSort',
  setup () {
    // 排序值(后期需要传递给后台列表接口)
    // null(默认)publishTime(最新)，orderNum(人气)， evaluateNum(评论)
    /* 高亮或选中思路
    1 定义一个当前点击或高亮的标识
    2根据第一步存的值,和所有元素的值对比 */
    // flag当前点击sort值
    const currSort = ref(null)
    const sortList = ref(sorts)
    // 获取过滤条件数据
    const filterParams = inject('filterParams')
    const changeSort = (sort) => {
      if (currSort.value === sort) return
      // console.log(sort)
      // 存储当前点击的排序条件值
      filterParams.value.sortField = sort
      currSort.value = sort
    }
    return { changeSort, sortList, currSort }
  }
}
</script>
<style scoped lang='less'>
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all 0.3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
          &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container {
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
</style>
